#ifndef KEYBOARD_H
#define KEYBOARD_H

#include <QWidget>
#include <QHash>
#include <QKeyEvent>

namespace Ui {
class KeyBoard;
}

class QPushButton;
class QHBoxLayout;
class QVBoxLayout;
class QGridLayout;
class QLayout;
class QPropertyAnimation;

class KeyBoard : public QWidget
{
    Q_OBJECT
    
public:
    explicit KeyBoard(QWidget *parent = 0);
    ~KeyBoard();

    void setShowKeyBoard(QObject *o, int type);

protected:
    bool eventFilter(QObject *, QEvent *);

private slots:
    void slotReceiveKeyClicked();
    bool dealButton(QObject *o);

private:
    void initbuttons();
    void initkeymapper();
    void setKeyboard(int type); //0：数字键盘；1：英文键盘
    void initDigitsBoard();
    void initAlphaBoard();
    void initSymbolBoard();
    void cleanDigitLayout();
    void cleanLayout123();
    void cleanSLayout123();
    void clearLayout(QLayout *layout);
    void initFocusOrder();
    
private:
    Ui::KeyBoard *ui;
    QHash<QString, QPushButton*> m_rbuttons;
    QHash<QString, int> m_keyMapper;
    QPushButton *m_ok, *m_delete,*m_upper, *m_symbol;
    bool m_isUpper;
    bool m_isSymbol;
    int m_currentBoard;
    QVBoxLayout *m_digitLeft, *m_digitRight;
    QGridLayout *m_digitCenter;
    QObject *m_o;
    QHBoxLayout *m_layout1;
    QHBoxLayout *m_layout2;
    QHBoxLayout *m_layout3;

    QHBoxLayout *m_slayout1;
    QHBoxLayout *m_slayout2;
    QHBoxLayout *m_slayout3;
    QPropertyAnimation *m_animation;
    QHash<QObject*, QList<QObject*> > m_ctrlOrder;
};

#endif // KEYBOARD_H
